package com.tql.mall.merchant.service.imp;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tql.mall.merchant.mapper.StockInfoMapper;
import com.tql.mall.merchant.service.StockInfoService;
import com.tql.mall.model.merchant.StockInfo;
import com.tql.mall.model.merchant.StockInfoQueryVo;
import org.springframework.stereotype.Service;

@Service
public class StockInfoServiceImpl extends ServiceImpl<StockInfoMapper, StockInfo> implements StockInfoService {

    @Override
    public Boolean checkoutStock(StockInfoQueryVo stockInfoQueryVo) {
        QueryWrapper<StockInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("sku_id",stockInfoQueryVo.getSkuId())
                        .eq("shop_id",stockInfoQueryVo.getShopId());
        StockInfo stockInfo = baseMapper.selectOne(queryWrapper);
        return (stockInfo.getNum() >= stockInfoQueryVo.getNum());
    }
}
